package three;

import java.util.Scanner;

/*
第一行，物品的种类n，背包体积的限制V，背包载重量的限制W。n,V和W的范围如前所述。
接下来n行，每行为该种物品i的体积vi，重量wi，数量ci，价值ti (规定vi,wi,ci和ti都为整数)
 */
public class test11083 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int v = scanner.nextInt();
        int w = scanner.nextInt();
        /*
        体积vi，重量wi，数量ci，价值ti
         */
        int[] v_arr = new int[n + 1];
        int[] w_arr = new int[n + 1];
        int[] c_arr = new int[n + 1];
        int[] t_arr = new int[n + 1];
        int[][][] m = new int[n + 1][v + 1][w + 1];
        for (int i = 1; i <= n; i++) {
            v_arr[i] = scanner.nextInt();
            w_arr[i] = scanner.nextInt();
            c_arr[i] = scanner.nextInt();
            t_arr[i] = scanner.nextInt();
        }
        q(m, v, w, n, v_arr, w_arr, c_arr, t_arr);
        System.out.println(m[n][v][w]);
    }

    private static void q(int[][][] m, int v, int w, int n, int[] v_arr, int[] w_arr, int[] c_arr, int[] t_arr) {
        int x = 0;
        int y = 0;
        int i = 0;
        int min = 0;
        int max = 0;
        int k = 0;
        int k_sum = 0;
        for (x = 0; x <= v; x++) {
            for (y = 0; y <= w; y++) {
                if ((x >= v_arr[1]) && (y >= w_arr[1])) {
                    min = Math.min(x / v_arr[1], y / w_arr[1]);
                    min = Math.min(min, c_arr[1]);
                    m[1][x][y] = min * t_arr[1];
                } else {
                    m[1][x][y] = 0;
                }
            }
        }
        for (i = 2; i <= n; i++) {
            for (x = 0; x <= v; x++) {
                for (y = 0; y <= w; y++) {
                    max = m[i - 1][x][y];
                    if ((x >= v_arr[i]) && (y >= w_arr[i])) {
                        min = Math.min(x / v_arr[i], y / w_arr[i]);
                        min = Math.min(min, c_arr[i]);
                        for (k = 1; k <= min; k++) {
                            k_sum = k * t_arr[i] + m[i - 1][x - k * v_arr[i]][y - k * w_arr[i]];
                            if (max < k_sum) {
                                max = k_sum;
                            }
                        }
                        m[i][x][y] = max;
                    } else {
                        m[i][x][y] = m[i - 1][x][y];
                    }
                }
            }
        }
    }
}
